﻿// <copyright file="CSRInfo.cs" company="Sinclair Community College">
// Copyright 2010 Sinclair Community College
// </copyright>
// <originalAuthor>Patrick S. Seymour (patrick.seymour@gmail.com)</originalAuthor>

namespace SinclairCC.AppV
{
    using System;

    public class CSRInfo
    {
        /// <summary>
        /// volume file version number
        /// </summary>
        private uint volumeVersion;

        private CSRINFO_FLAGS flags;

        /// <summary>
        /// Size of a container.
        /// </summary>
        private uint csrBlockSize;

        /// <summary>
        /// Size of a storage block.
        /// </summary>
        private uint stBlockSize;

        /// <summary>
        /// The maximum size, in MB, that this volume can be grown without extending the storage
        /// allocation map.
        /// </summary>
        private uint fileSize;

        /// <summary>
        /// Initializes a new instance of the CSRInfo class.
        /// </summary>
        public CSRInfo(System.IO.BinaryReader fileReader)
        {
            // The default container size is 512 bytes.
            this.csrBlockSize = 512;

            // The default storage block size is 4096 bytes.
            this.stBlockSize = 4096;

            this.ReadContainer(fileReader);
        }

        /// <summary>
        /// Reads the actual data for this container from the file.
        /// </summary>
        protected void ReadContainer(System.IO.BinaryReader fileReader)
        {
            this.volumeVersion = fileReader.ReadUInt32();

            uint rawUInt = fileReader.ReadUInt32();

            if (Enum.IsDefined(typeof(CSRINFO_FLAGS), rawUInt))
            {
                this.flags = (CSRINFO_FLAGS)rawUInt;
            }

            this.csrBlockSize = fileReader.ReadUInt32();
            this.stBlockSize = fileReader.ReadUInt32();
            this.fileSize = fileReader.ReadUInt32();
        }

        /// <summary>
        /// Gets the volume file version number.
        /// </summary>
        public uint VolumeVersion
        {
            get { return this.volumeVersion; }
        }

        public CSRINFO_FLAGS Flags
        {
            get { return this.flags; }
        }

        /// <summary>
        /// Gets the size of a container.
        /// </summary>
        public uint ContainerBlockSize
        {
            get { return this.csrBlockSize; }
        }

        /// <summary>
        /// Gets the size of a storage block.
        /// </summary>
        public uint StorageBlockSize
        {
            get { return this.stBlockSize; }
        }

        /// <summary>
        /// Gets the maximum size, in MB, that this volume can be grown without extending the
        /// storage allocation map.
        /// </summary>
        public uint MaxVolumeSize
        {
            get { return this.fileSize; }
        }
    }
}
